package com.jeecg.filter;

import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.jeecg.util.AnnotiontionUtil;
import com.jeecg.util.ClassUtil;
/**
 * 系统加载后，扫描指定目录下文件的注解，把注解存入map中
 * @author lifei
 *
 */

public class AnnotationListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent servletcontextevent) {
		System.out.println("信息AnnotationListener：系统已经注销！");
	}

	@Override
	public void contextInitialized(ServletContextEvent servletcontextevent) {
		ServletContext context= servletcontextevent.getServletContext();
		String path=Thread.currentThread().getContextClassLoader().getResource("").getPath();
		String basePackage=context.getInitParameter("base-package");
		//得到包下所有的类
		Set<String> classNames=ClassUtil.getClassName(basePackage, true);
		//初始化mvc映射
		AnnotiontionUtil.getAnnotationFiles(classNames);
		System.out.println("annotation_mvc初始化完毕！");
	}

}
